package com.soboot.auth;

import com.soboot.log.utils.LogUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

/**
 * @Author:
 * @createTime: 2022年09月20日 15:38:29
 * @version: 1.0
 * @Description: 认证中心启动类
 * @Copyright:
 */
@RefreshScope
@EnableFeignClients("com.soboot.system.feign")
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"com.soboot.*"})
public class AuthApplication {

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(AuthApplication.class);
        //记录应用PID写入当前目录application.pid下
        springApplication.setAllowBeanDefinitionOverriding(true);
        springApplication.addListeners(new ApplicationPidFileWriter());
        springApplication.run(args);
        LogUtil.info("认证服务启动成功!");
    }

    @Bean("restTemplate")
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(
                MediaType.APPLICATION_JSON,
                MediaType.TEXT_HTML,
                MediaType.TEXT_PLAIN));
        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);

        return restTemplate;
    }
}
